Web Forms

Table of contents

Introduction

This article describes the web-form endpoint, which lets you register a contact in Fideltour from any form installed on the customer's website.

  • Endpoint: POST https://app.hoteldatahub.io/api/v1/contacts/web-form/
  • Swagger: https://app.hoteldatahub.io/swagger/#/contacts/contacts_web_form

The contact is uniquely identified by their email: if a contact already exists with that email it is updated, and if not, it is created.

Parameter table

Field Type Required Description
hotel_chain String Yes Hotel chain code, provided by Fideltour.
api_user String Yes (*) API user's username, provided by Fideltour. Required unless company_id is sent.
company_id Integer No (*) Company identifier. Alternative to api_user: one of the two must be sent.
email String Yes Contact's email. Unique field, used as the contact's identifier.
source Integer No Contact source:
• 6 = Newsletter form (default)
• 7 = Contact form
If a different value is sent, 6 (newsletter form) is used.
name String No Contact's first name.
surname String No Contact's last name.
language String No Contact's language. Must be in ISO 639-1 format.
country String No Contact's country. Must be in ISO 3166-1 alpha-2 format.
phone1 String No Contact's phone number.
birthday Date YYYY-MM-DD No Date of birth.
address String No Address.
post_code String No Postal code.
province String No Name of the province.
town String No Name of the town or city.
zone String No Name of the zone.
identification_document_type Integer No Identity document type:
• 0 = Other
• 1 = National ID
• 2 = Foreigner ID
• 3 = Passport
identification_number String No Identity document number.
gender Integer No Gender:
• 0 = Not specified (default)
• 1 = Male
• 2 = Female
• 3 = Non-binary
• 4 = Genderfluid
• 5 = Prefer not to say
custom_tags Array of String No Names of the tags to link with the contact.
business_name String No Company name.
work_place String No Job title.
business_address String No Company address.
fiscal_address String No Fiscal address.
accept_terms Boolean No Indicates whether the contact accepts the terms and conditions.
• true = Accepts
• false = Does not accept (default)
accept_commercial_communications Boolean No Indicates whether the contact accepts marketing communications.
• true = Accepts
• false = Does not accept (default)
accept_personalized_commercial_communications Boolean No Indicates whether the contact accepts personalized marketing communications.
• true = Accepts
• false = Does not accept (default)
ip String No IP address from which the legal checkboxes were accepted.

(*) You must send either api_user or company_id. hotel_chain must match the given api_user (or company_id).

Important: if the API user (given directly or resolved from company_id) is deactivated, the request is rejected with a 403 and the contact is not registered in Fideltour.

Note: the Boolean values true and false can also be sent as integers 1 and 0.

Example

Below is an example of a request and a successful response.

Request (POST)

The following example shows a request to create the contact pablo@hdh.com.

  • Protocol: HTTP/1.1
  • Method: POST
  • Host/Endpoint: https://app.hoteldatahub.io/api/v1/contacts/web-form/
  • Headers: Content-type: application/json
{
    "hotel_chain": "6NOK",
    "api_user": "hoteldatahub_fideltour_web_form",
    "email": "pablo@hdh.com",
    "birthday": "1976-04-18",
    "phone1": "651442233",
    "gender": 2,
    "address": "Calle los olivos",
    "province": "Madrid",
    "town": "Madrid",
    "zone": "Sol",
    "post_code": "28013",
    "language": "es",
    "country": "ES",
    "name": "Pablo",
    "surname": "Mir",
    "identification_document_type": 1,
    "identification_number": "01234567Z",
    "source": 6,
    "custom_tags": ["VIP Customer", "Tourist"],
    "accept_terms": true,
    "accept_commercial_communications": true,
    "accept_personalized_commercial_communications": false
}

Response

For a 200 or 201 response, the JSON you receive has the following structure.

{
    "id": 9999999,
    "business_name": null,
    "work_place": "Madrid",
    "business_address": null,
    "fiscal_address": "Calle de las soluciones industriales 25",
    "language": "ES",
    "country": "ES",
    "created_at": "2022-01-01T12:12:12.654321",
    "level_name": "",
    "loyalty_card_number": null,
    "name": "Pablo",
    "surname": "Mir",
    "email": "pablo@hdh.com",
    "email_status": 0,
    "phone1": "651442233",
    "gender": 2,
    "identification_document_type": 1,
    "identification_number": "01234567Z",
    "birthday": "1976-04-18",
    "address": "Calle los olivos",
    "post_code": "07006",
    "source": 1,
    "notes": "Very demanding",
    "photo": null,
    "subscribed": false,
    "unsubscribe_reason": null,
    "date_subscribed": "2022-01-01T12:12:12.654321",
    "modification_date_subscribed": null,
    "is_active": true,
    "points": 0,
    "value": 0,
    "review": null,
    "total_bookings": 0,
    "level_points": 0,
    "loyalty_custom_tag_timestamp": null,
    "is_profile_completed": false,
    "last_level_review": null,
    "kicked_out_loyalty": null,
    "province": 1,
    "town": 2,
    "zone": 3,
    "level": null,
    "custom_tags": [4, 5],
    "hotels": []
}

Note: in the response, the province, town, zone and custom_tags fields are returned as Fideltour's numeric identifiers, not the names sent in the request.

Newsletter subscription form

Below is the HTML and JavaScript code needed to build an example newsletter subscription form integrated with Fideltour.

<form id="fideltour-newsletter-form" method="POST">
    <input type="hidden" name="hotel_chain" value="ASK FIDELTOUR">
    <input type="hidden" name="api_user" value="ASK FIDELTOUR">
    <div>
        <label for="name">Name</label>
        <input id="name" type="text" name="name">
    </div>
    <div>
        <label for="surname">Last name</label>
        <input id="surname" type="text" name="surname">
    </div>
    <div>
        <label for="email">Email</label>
        <input id="email" type="text" name="email" required>
    </div>
    <div>
        <input id="accept" type="checkbox" name="accept_commercial_communications" required>
        <label for="accept">
            I agree to subscribe to the newsletter to receive marketing communications
        </label>
    </div>
    <button type="submit">Submit</button>
</form>

<script type="text/javascript">
    const endpoint = "https://app.hoteldatahub.io/api/v1/contacts/web-form/";
    const form = document.getElementById("fideltour-newsletter-form");

    form.addEventListener("submit", function (e) {
        e.preventDefault();
        const xhr = new XMLHttpRequest();
        xhr.open("POST", endpoint, true);
        xhr.setRequestHeader("Content-type", "application/json");

        const formData = new FormData(form);
        const data = {};
        formData.forEach((value, key) => {
            if (value) {
                if (value === "on") value = true;
                data[key] = value;
            }
        });

        xhr.send(JSON.stringify(data));
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    // Request completed successfully
                    console.log("Response received:", xhr.responseText);
                } else {
                    // There was a problem with the request
                    console.error("Request error:", xhr.statusText);
                }
            }
        };
    });
</script>